package com.code.task.job;

import com.code.task.service.IndexTaskService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lyf
 * @date 2021-06-15 下午3:34
 */
@Component
public class IndexJob {

    @Autowired
    private IndexTaskService indexTaskService;

    @XxlJob(value = "indexItem",destroy = "stopIndexItem")
    public ReturnT<String> indexAllItem(String param) {
        indexTaskService.indexAll(XxlJobHelper.getShardTotal(), XxlJobHelper.getShardIndex());
        return ReturnT.SUCCESS;
    }

    public void stopIndexItem() {
        indexTaskService.cancelIndexAll();
        XxlJobHelper.log("indexAllItem stop successfully");
    }
}
